package com.gainloop.Api.Entity;

import java.util.Date;

import com.gainloop.Api.ApiException;
import com.google.gson.annotations.SerializedName;

public class User extends EntityAbstract {
	
	public enum GENDER {
		UNKNOWN,
		MALE,
		FEMALE
	}

	@SerializedName("id")
	public long _id;

	@SerializedName("fbId")
	public long _fbId;
		
	@SerializedName("name")
	public String _name;

	@SerializedName("email")
	public String _email;
		
	@SerializedName("createTime")
	private long _createTime;

	@SerializedName("birthday")
	private long _birthday;

	@SerializedName("locationName")
	public String _locationName;

	@SerializedName("locationId")
	public long _locationId;

	@SerializedName("gender")
	private char _gender;

	@SerializedName("country")
	public String _country;

	@SerializedName("locale")
	public String _locale;

	@SerializedName("lastChangeTime")
	private long _lastChangeTime;

	@SerializedName("wishesNum")
	private long _wishesNum;

	@SerializedName("helpsNum")
	private long _helpsNum;

	@SerializedName("resolvedNum")
	private long _resolvedNum;

	@SerializedName("friendsNum")
	private long _friendsNum;
	
	
	public User(){
		_createTime=new Date().getTime()/ 1000;
	}
	public long getId()
	{
		return this._id;
	}
	
	public long getFbId()
	{
		return this._fbId;
	}
	
	public void setFbId(long fbId)
	{
		if(fbId < 0) {
			throw new ApiException("User fbId must be unsigned");
		}
		this._fbId = fbId;
	}
	
	public String getName()
	{
		return this._name;
	}
	
	public void setName(String name)
	{
		this._name = name;
	}
	
	public String getEmail()
	{
		return this._email;
	}
	
	public void setEmail(String email)
	{
		this._email = email;
	}
	
	public Date getCreateTime()
	{
		return new Date(_createTime * 1000);
	}
	
	public Date getBirthday()
	{
		return new Date(_birthday * 1000);
	}
	
	public void setBirthday(Date birthday)
	{
		_birthday = birthday.getTime() / 1000;
	}
	
	public String getLocationName()
	{
		return this._locationName;
	}
	
	public void setLocationName(String locationName)
	{
		this._locationName = locationName;
	}
	
	public long getLocationId()
	{
		return this._locationId;
	}
	
	public void setLocationId(long locationId)
	{
		if(locationId < 0) {
			throw new ApiException("User location id must be unsigned");
		}
		this._locationId = locationId;
	}
	
	public GENDER getGender()
	{
		if(_gender == 'm') {
			return GENDER.MALE;
		} else if(_gender == 'f') {
			return GENDER.FEMALE;
		} else  {
			return GENDER.UNKNOWN;
		}
	}
	
	public void setGender(GENDER gender)
	{
		if(gender == GENDER.MALE) {
			_gender = 'm';
		} else if(gender == GENDER.FEMALE) {
			_gender = 'f';
		} else {
			_gender = 'x';
		}
	}
	
	public String getCountry()
	{
		return this._country;
	}
	
	public void setCountry(String country)
	{
		this._country = country;
	}
	
	public String getLocale()
	{
		return this._locale;
	}
	
	public void setLocale(String locale)
	{
		this._locale = locale;
	}
	
	public void setLocale(String language, String country)
	{
		this._locale = language + "_" + country;
	}
	
	public Date getLastChangeTime()
	{
		return new Date(this._lastChangeTime * 1000);
	}
	
	public long getWishesNum()
	{
		return this._wishesNum;
	}
	
	public long getHelpsNum()
	{
		return this._helpsNum;
	}
	
	public long getResolvedNum()
	{
		return this._resolvedNum;
	}
	
	public long getFriendsNum()
	{
		return this._friendsNum;
	}
	
	public String toString()
	{
		return "User[" + this._name + ", " + this._id + "]";
	}
}
